import type { IStack } from '../type'

/**
 * @author hzq
 * @description 数组实现栈
 * @date 2024-11-3
 */
class ArrayStack<T> implements IStack<T> {
  private _arr: T[]
  constructor() {
    this._arr = []
  }
  pop(): T | undefined {
    return this._arr.pop()
  }
  peek(): T | undefined {
    return this._arr.at(-1)
  }
  isEmpty(): boolean {
    return this._arr.length === 0
  }
  clear(): void {
    this._arr.length = 0
  }
  get size(): number {
    return this._arr.length
  }
  push(item: T): number {
    return this._arr.push(item)
  }
}
export default ArrayStack
